package cn.iocoder.an.module.business.service.equipmentcheckrecorddetail;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.an.module.business.controller.admin.equipmentcheckrecorddetail.vo.*;
import cn.iocoder.an.module.business.dal.dataobject.equipmentcheckrecorddetail.EquipmentCheckRecordDetailDO;
import cn.iocoder.an.framework.common.pojo.PageResult;
import cn.iocoder.an.framework.common.pojo.PageParam;
import cn.iocoder.an.framework.common.util.object.BeanUtils;

import cn.iocoder.an.module.business.dal.mysql.equipmentcheckrecorddetail.EquipmentCheckRecordDetailMapper;

import static cn.iocoder.an.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.an.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.an.module.business.enums.ErrorCodeConstants.*;

/**
 * 点检记录明细 Service 实现类
 *
 * @author zzy
 */
@Service
@Validated
public class EquipmentCheckRecordDetailServiceImpl implements EquipmentCheckRecordDetailService {

    @Resource
    private EquipmentCheckRecordDetailMapper equipmentCheckRecordDetailMapper;

    @Override
    public Long createEquipmentCheckRecordDetail(EquipmentCheckRecordDetailSaveReqVO createReqVO) {
        // 插入
        EquipmentCheckRecordDetailDO equipmentCheckRecordDetail = BeanUtils.toBean(createReqVO, EquipmentCheckRecordDetailDO.class);
        equipmentCheckRecordDetailMapper.insert(equipmentCheckRecordDetail);

        // 返回
        return equipmentCheckRecordDetail.getId();
    }

    @Override
    public void updateEquipmentCheckRecordDetail(EquipmentCheckRecordDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateEquipmentCheckRecordDetailExists(updateReqVO.getId());
        // 更新
        EquipmentCheckRecordDetailDO updateObj = BeanUtils.toBean(updateReqVO, EquipmentCheckRecordDetailDO.class);
        equipmentCheckRecordDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteEquipmentCheckRecordDetail(Long id) {
        // 校验存在
        validateEquipmentCheckRecordDetailExists(id);
        // 删除
        equipmentCheckRecordDetailMapper.deleteById(id);
    }

    @Override
        public void deleteEquipmentCheckRecordDetailListByIds(List<Long> ids) {
        // 删除
        equipmentCheckRecordDetailMapper.deleteByIds(ids);
        }


    private void validateEquipmentCheckRecordDetailExists(Long id) {
        if (equipmentCheckRecordDetailMapper.selectById(id) == null) {
            throw exception(EQUIPMENT_CHECK_RECORD_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public EquipmentCheckRecordDetailDO getEquipmentCheckRecordDetail(Long id) {
        return equipmentCheckRecordDetailMapper.selectById(id);
    }

    @Override
    public PageResult<EquipmentCheckRecordDetailDO> getEquipmentCheckRecordDetailPage(EquipmentCheckRecordDetailPageReqVO pageReqVO) {
        return equipmentCheckRecordDetailMapper.selectPage(pageReqVO);
    }

}